import { View } from "@tarojs/components"
import React, { Component } from "react"
import { connect } from 'react-redux'
import { findCabinets, getCabinets } from "src/actions/cabinets"
import { setCabinetId, setLocationVisible } from "src/actions/global"
import { locationUpdate } from "src/actions/location"
import { loginWXMP, refershToken } from "src/actions/login"
import { getToken, getUser, setUser } from "src/actions/user"

class GoodsDetail extends Component {
  render() {
    return (
      <View>
        GoodsDetail
      </View>
    )
  }
}


// 将 reducer 中的状态插入到组件的 props 中
// 下面是单个reducer的时候，多个的时候需要选传入哪个reducer
// const { test, count } = state
const mapStateToProps = (state) => ({
  user: state.user,
  login: state.login,
  cabinets: state.cabinets.cabinets,
  detailLogin: state.cabinets.detailLogin,
  cabinet: state.cabinets.cabinet,
  location: state.global.location
})

// 将 对应action 插入到组件的 props 中
const mapDispatchToProps = (dispatch) => ({
  getUser () {
    dispatch(getUser())
  },
  getToken () {
    dispatch(getToken())
  },
  setUser (user) {
    dispatch(setUser(user))
  },
  refershToken (token) {
    dispatch(refershToken(token))
  },
  toLogin () {
    dispatch(loginWXMP())
  },
  updateLocation() {
    dispatch(locationUpdate())
  },
  updateCabinets () {
    dispatch(findCabinets())
  },
  getCabinets (id) {
    dispatch(getCabinets(id))
  },
  setCabinetId (id) {
    dispatch(setCabinetId(id))
  },
  setLocationVisible (visible, type) {
    dispatch(setLocationVisible(visible, type))
  }
})

// 使用 connect 高阶组件对 Counter 进行包裹
export default connect(mapStateToProps, mapDispatchToProps)(GoodsDetail)